﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using BLL;
using Model;

public partial class ModifyTest_ModifyTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {  
            BindTest();
        }
    }

    protected void BindTest()
    {
        Test test = new Test();
        Guid guid1 = (Guid)Session["TestID"];
        //TextBox1.Text = guid1.ToString();
        //if (guid1 != null)
        {
            IList<TestInfo> tests = new List<TestInfo>();
            tests.Add(test.GetTest(guid1));
            GridView1.DataSource = tests;
            GridView1.DataBind();
        }
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindTest();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TestInfo testInfo = new TestInfo();
        testInfo.TestID = (Guid)Session["TestID"];
        testInfo.ProductSN = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[0].Controls[0])).Text.Trim().ToString();
        testInfo.TestTime = Convert.ToDateTime(((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text);
        testInfo.ProductTypeID = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.Trim().ToString();
        testInfo.UserID = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.Trim().ToString();
        testInfo.ENAID = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.Trim().ToString();
        testInfo.IsPass = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.Trim().ToString();
        testInfo.IsSwitch = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[6].Controls[0])).Text.Trim().ToString();

        Test test1 = new Test();
        test1.Update(testInfo);

        //TextBox2.Text = testInfo.IsPass;
        //TextBox3.Text = testInfo.IsSwitch;

        GridView1.EditIndex = -1;
        BindTest();

        //TextBox4.Text = GridView1.Rows[0].Cells[5].Text.ToString();
        //TextBox5.Text = GridView1.Rows[0].Cells[6].Text.ToString();
    }

    protected void GridView1_RowCanncelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindTest();
    }
}
    

